package com.ping.study.service.impl;

import com.ping.study.mapper.GamesMapper;
import com.ping.study.pojo.Games;
import com.ping.study.service.GamesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GamesServiceImpl implements GamesService {

    @Autowired
    private GamesMapper gamesMapper;
    //先查询数据库有没有比赛信息
    public Games getGames(String gameId) {
        return gamesMapper.selectByGameId(gameId);
    }
    @Override
    public void insertGames(Games games) {
        if (getGames(games.getGameId())!=null){
            //抛出异常
            throw new RuntimeException("该比赛已存在");
        }
        gamesMapper.insert(games);
    }

    @Override
    public List<Games> getGames() {

        return gamesMapper.selectAll();
    }

    @Override
    public void deleteAllGames() {
        gamesMapper.deleteAllGames();
    }
}
